package com.diyunapp.xilinapp.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.bean.GoodsSortsMiddleBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SortsTopAdapter extends BaseAdapter {

    private Context mContext;
    private List<GoodsSortsMiddleBean> mLists;

    public SortsTopAdapter(Context mContext, List<GoodsSortsMiddleBean> mLists) {
        super();
        this.mContext = mContext;
        this.mLists = mLists;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mLists.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.goodsort_top_list, null);
            holder = new ViewHolder(convertView);
            // 得到组件信息，将组件信息处理，显示在屏幕上
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        GoodsSortsMiddleBean list = mLists.get(position);
        holder.toplistSorttitleTv.setText(list.getSortTitle());
        if (list.isIfDisplay()) {
            holder.topSelectFl.setVisibility(View.VISIBLE);
            if (list.isBeSelected()) {
                holder.topSelectedLineView.setVisibility(View.VISIBLE);
                holder.topUnselectedLineView.setVisibility(View.GONE);
            } else {
                holder.topSelectedLineView.setVisibility(View.GONE);
                holder.topUnselectedLineView.setVisibility(View.VISIBLE);
            }
        } else {
            holder.topSelectFl.setVisibility(View.GONE);
        }
        return convertView;
    }

    static  class ViewHolder {
        @Bind(R.id.toplist_sorttitle_tv)
        TextView toplistSorttitleTv;
        @Bind(R.id.top_unselected_line_view)
        ImageView topUnselectedLineView;
        @Bind(R.id.top_selected_line_view)
        ImageView topSelectedLineView;
        @Bind(R.id.top_select_fl)
        FrameLayout topSelectFl;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
